/*************************************************************************
 * File Name:    Merge_Sorted_Array.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Sat 02 Nov 2013 02:05:01 PM CST
 * 
 * Description:  
 |-----------------------------------------------------------------------
 | Problem: Merge Sorted Array
 | Given two sorted integer arrays A and B, merge B into A as one sorted array.
 |
 | Note:
 | You may assume that A has enough space to hold additional elements from B.
 | The number of elements initialized in A and B are m and n respectively.
 |-----------------------------------------------------------------------
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iomanip>

using namespace std;

class Solution {
public:
    void merge(int A[], int m, int B[], int n) {
        int pa = m - 1;
        int pb = n - 1;
        
        while (pa >= 0 && pb >= 0) {
            if (A[pa] > B[pb]) {
                A[pa + pb + 1] = A[pa];
                --pa;
            } else {
                A[pa + pb + 1] = B[pb];
                --pb;
            }
        }
        while (pb >= 0) {
            A[pb] = B[pb];
            --pb;
        }
    }
};
